package com.bdmc.smokesensor.Utils;

import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {

    public static String dateToString(Date date){
        java.text.DateFormat format1 = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String s = format1.format(date);
        return s;
    }

    public static Date stringToDate(String date) throws ParseException{
        java.text.DateFormat format1 = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date d = format1.parse(date);
        return d;
    }

    public static Date dateAddMinute(Date date,int minute){
        Calendar rightNow = Calendar.getInstance();
        rightNow.setTime(date);
        rightNow.add(Calendar.MINUTE,minute);
        Date dt1=rightNow.getTime();
        return dt1;
    }

    public static Date dateAddHour(Date date,int hour){
        Calendar rightNow = Calendar.getInstance();
        rightNow.setTime(date);
        rightNow.add(Calendar.HOUR,hour);
        Date dt1=rightNow.getTime();
        return dt1;
    }

    public static Date dateAddDay(Date date,int day){
        Calendar rightNow = Calendar.getInstance();
        rightNow.setTime(date);
        rightNow.add(Calendar.DATE,day);
        Date dt1=rightNow.getTime();
        return dt1;
    }

}